package cn.janyd.jmall.dubbo.core.web;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author janyd
 * @since 2020/8/5 20:28
 */
public class DubboI18nInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        DubboLocaleContextHolder.setLocale(RequestContextUtils.getLocale(request));
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        DubboLocaleContextHolder.clear();
    }
}
